package com.cookie.module_constellation.fragment

import android.widget.Toast
import com.cookie.lib_base.base.BaseFragment
import com.cookie.lib_network.HttpManager
import com.cookie.lib_network.bean.YearData
import com.cookie.module_constellation.R
import kotlinx.android.synthetic.main.fragment_year.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

/**
 *   文件名:    YearFragment
 *   创建者:    cookie
 *   创建时间:   2020/10/23 11:33
 *   描述:      TODO
 */
class YearFragment(val name: String) : BaseFragment() {
    override fun getLayoutId(): Int {
        return R.layout.fragment_year
    }

    override fun initView() {
        loadYearData()
    }

    private fun loadYearData() {
        HttpManager.queryYearConstellInfo(name, object : Callback<YearData> {
            override fun onFailure(call: Call<YearData>, t: Throwable) {
                Toast.makeText(activity, "加载失败", Toast.LENGTH_SHORT).show()
            }

            override fun onResponse(call: Call<YearData>, response: Response<YearData>) {
                val data = response.body()
                data?.let {
                    tvName.text = it.name
                    tvDate.text = it.date
                    tvInfo.text = it.mima.info
                    tvInfoText.text = it.mima.text[0]
                    tvCareer.text = it.career[0]
                    tvLove.text = it.love[0]
                    tvFinance.text = it.finance[0]
                }
            }
        })
    }
}